package com.happyfamily.springboot.crowdsourcingplatform.controller.wang;

import com.happyfamily.springboot.crowdsourcingplatform.annotation.OperationLogDetail;
import com.happyfamily.springboot.crowdsourcingplatform.base.result.PageTableRequest;
import com.happyfamily.springboot.crowdsourcingplatform.base.result.Results;
import com.happyfamily.springboot.crowdsourcingplatform.enums.OperationType;
import com.happyfamily.springboot.crowdsourcingplatform.enums.OperationUnit;
import com.happyfamily.springboot.crowdsourcingplatform.model.Credit;
import com.happyfamily.springboot.crowdsourcingplatform.model.SysUser;
import com.happyfamily.springboot.crowdsourcingplatform.service.wang.CreditService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

/**
 * 信用分查询的控制类
 */
@Controller
@Slf4j
public class CreditController
{
	@Autowired
	private CreditService creditServiceImpl;


	/**
	 * 门户查询账户的信誉分
	 *
	 * @param uaccount
	 * @return
	 */
	@ApiOperation(value = "门户查询账户的信誉分", notes = "门户查询账户的信誉分")
	@OperationLogDetail(detail = "门户查询账户的信誉分", level = 1, operationUnit = OperationUnit.USER, operationType = OperationType.SELECT)
	@PostMapping("/credit/searchCredit")
	@ResponseBody
	public SysUser searchCredit(String uaccount)
	{
		return creditServiceImpl.searchCredit(uaccount);
	}

	/**
	 * 切换查看我的信用明细弹窗
	 *
	 * @return
	 */
	@ApiOperation(value = "切换查看我的信用明细弹窗", notes = "切换查看我的信用明细弹窗")
	@GetMapping("/api-front/credit/myCredit")
	public String myCredit()
	{
		return "frontPage/mycredit-list";
	}

	/**
	 * 查看我的信用分明细
	 *
	 * @param starttime
	 * @param endtime
	 * @param request
	 * @param ptr
	 * @return
	 */
	@ApiOperation(value = "查看我的信用分明细", notes = "查看我的信用分明细")
	@OperationLogDetail(detail = "查看我的信用分明细", level = 1, operationUnit = OperationUnit.USER, operationType = OperationType.SELECT)
	@RequestMapping("/api-front/credit/creditList")
	@ResponseBody
	public Results<Credit> creditList(String starttime, String endtime, HttpServletRequest request, PageTableRequest ptr)
	{
		ptr.countOffset();
		return creditServiceImpl.creditList(ptr.getOffset(), ptr.getLimit(), starttime, endtime, request);
	}

}
